package logic

import (
	"encoding/binary"

	"github.com/minio/highwayhash"
)

var _Key32 = []byte("logic author xuender, 2020-10-11")

// Fact 事实
type Fact struct {
	ID       uint64
	Relation Relation
	Name     string
	Target   string
	Others   []string
}

// NewFact 新建事实
func NewFact(relation Relation, name, target string, others ...string) *Fact {
	f := &Fact{
		Relation: relation,
		Name:     name,
		Target:   target,
		Others:   others,
	}
	hash, _ := highwayhash.New64(_Key32)
	var buf = make([]byte, 8)
	binary.BigEndian.PutUint64(buf, uint64(relation))
	hash.Write(buf)
	hash.Write([]byte(name))
	hash.Write([]byte(target))
	for _, o := range others {
		hash.Write([]byte(o))
	}
	f.ID = hash.Sum64()
	return f
}

// Filter 过滤
// func (f *Fact) Filter(facts []*Fact) []*Fact {
// 	fs := []*Fact{}
// 	for _, fact := range facts {
// 		if f.Name == fact.Name {
// 			fs = append(fs, fact)
// 		}
// 	}
// 	return fs
// }
